package com.biu.billiards.controller;
import com.biu.billiards.config.OperationAnnotation;
import com.biu.billiards.model.Login.AdminLoginVo;
import com.biu.billiards.model.vo.admin.AddAdminVo;
import com.biu.billiards.model.vo.admin.GetAdminVo;
import com.biu.billiards.model.vo.admin.UpdateAdminVO;
import com.biu.billiards.response.BaseResponse;
import com.biu.billiards.response.RespGenerator;
import com.biu.billiards.service.IAdminService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xue
 * @since 2023-09-25
 */
@RestController
@RequestMapping()
public class AdminController {

    @Resource
    private IAdminService adminService;


    @ApiOperation(value = "token登录")
    @PostMapping("/token/login")
    @OperationAnnotation(content="管理员登录",sysType=0,opType=0,action="后台登录接口")
    public BaseResponse<HashMap> tokenLogin(HttpServletRequest request) {
        return RespGenerator.returnOK(adminService.tokenLogin(request));
    }

    @ApiOperation(value = "后台登录")
    @PostMapping("/admin/login")
    @OperationAnnotation(content="管理员登录",sysType=0,opType=0,action="登录接口")
    public BaseResponse<HashMap> appLogin(@RequestBody AdminLoginVo adminLoginVo, HttpServletRequest request) {

        return RespGenerator.returnOK(adminService.adminLogin(adminLoginVo,request));
    }


    @ApiOperation(value = "获取分页管理员数据")
    @PostMapping("/getAdminPage")
    public BaseResponse<Map<String,Object>> getAdminPage(@RequestBody GetAdminVo getAdminVo) {

        return RespGenerator.returnOK(adminService.getAdminList(getAdminVo));
    }


    @ApiOperation(value = "修改管理员信息")
    @PutMapping("/updateAdmin")
    public BaseResponse<Boolean> updateAdmin(@RequestBody UpdateAdminVO updateAdminVO) {
        return RespGenerator.returnOK(adminService.updateAdmin(updateAdminVO));
    }


    @ApiOperation(value = "新增管理员信息")
    @PostMapping("/addAdmin")
    public BaseResponse<Boolean> addAdmin(@RequestBody AddAdminVo addWallVo) {

        return RespGenerator.returnOK(adminService.addAdmin(addWallVo));
    }


    @ApiOperation(value = "删除管理员信息")
    @DeleteMapping("/deleteAdmin")
    public BaseResponse<Boolean> deleteAdmin(@RequestParam("adminId") Integer adminId) {
        System.out.println("adminId");
        System.out.println(adminId);
        return RespGenerator.returnOK(adminService.deleteAdmin(adminId));
    }

}
